class ProductBacklogsController < UserStoriesController
  before_filter :productBacklog_allow_show, :expect => []
  def productBacklog_allow_show
    if current_user #&& current_user_role.ProductBacklog == true
      return true
    else
      render :partial => "layouts/denied"
      return false
    end
  end
  #private
  def show
    new_project_id = params[:active_project_id]
    
    unless new_project_id.nil?
        current_user.update_attribute(:current_project_id, new_project_id)
    end
    
    # Finde das Product Backlog zum aktuellen Projekt oder,
    # falls dieses noch nicht existiert, erstelle es.
    @productBacklog = ProductBacklog.find_or_create_by_project_pid(current_user.current_project_id)
    @sort = "user_story_priority_pid"
    @user_story = UserStory.find_all_by_product_backlog_pid(@productBacklog.id, :order => @sort,  :conditions => {:user_story_state_pid => [UserStoryState.find_by_status("Offen").id, UserStoryState.find_by_status("Entwurf").id, UserStoryState.find_by_status("Zu&nbsp;pr&uuml;fen").id]})
    @story_states = Hash.new
    
    
    UserStoryState.all.each do |state|
        unless state.status == "Im&nbsp;Sprintbacklog" or state.status == "Abgenommen"
            @story_states[state.status.html_safe] = state.id
        end
    end
    
    
    unless new_project_id.nil?
      render :layout => nil
    end
  end
end